# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/9/13
# @File : 1.D - Knapsack 1.py

N,W = map(int ,input().split())
dp = [0]*(W+1)
for _ in range(N):
    w,v = map(int,input().split())
    for j in range(W,w -1,-1):
        dp[j] = max(dp[j],dp[j-w]+v)
print(dp[W])